package org.luxor.commons.redis.service;

import org.luxor.commons.redis.annotation.LimitRate;
import org.luxor.commons.redis.annotation.RedisCacheable;
import org.luxor.commons.redis.model.User;
import org.springframework.stereotype.Service;

/**
 * @author Mr.yan @date 2019/10/12
 */
@Service
public class UserService {

    @RedisCacheable(cacheNames = "UserService", keys = {"#user.id"}, expireTime = 120)
    public User getCacheUser(User user) {
        System.out.println("从数据库中获取User,id=" + user.getId());
        return new User(user.getId(), "@Cacheable");
    }

    @LimitRate(key = "#user.id")
    public User getUser(User user) {
        System.out.println("从数据库中获取User,id=" + user.getId());
        return new User(user.getId(), "@LimitRate");
    }
}
